import axios from 'axios'
import { message } from 'antd'


// export const imgServer = 'http://baixue.llyyjj.com/'
export const imgServer = 'http://wrobot.tianshuyunkeji.com/'

export const baseURL = imgServer + 'api/'
var instance = axios.create({
  baseURL,
  timeout: 5000,
  // headers: { 'X-Custom-Header': 'foobar' }
});
export default function http(url, data = {}, method = "GET", showSuccess) {
  return new Promise((resolve, reject) => {
    let request
    if (method === "GET") {
      request = instance.get(url, { params: data })
    } else if (method === "POST") {
      request = instance.post(url, data)
    } else if (method === "DELETE") {
      request = instance.delete(url)
    }
    request.then(res => {
      if (showSuccess) {
        message.success('操作成功！')
      }
      resolve(res)
    }).catch(err => {
      if (err.response && err.response.status === 400 && typeof err.response.data === 'string') {
        message.error(err.response.data)
      } else {
        message.error('服务器出错！')
      }
      reject(err)
    })
  })
}